add_compile_options(-flto -fsanitize=address -fno-omit-frame-pointer)
add_compile_options(-Wno-array-bounds -Wno-format-truncation)
add_compile_options(-Wall -Werror)
add_definitions(-DCONFIG_VERSION="2023-12-09" -DCONFIG_BIGNUM)
add_definitions(-D_GNU_SOURCE -D__USE_MINGW_ANSI_STDIO)
add_link_options(-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive)

set(QJS_COMM_SRC cutils.c libbf.c libregexp.c libunicode.c quickjs.c quickjs-libc.c)
add_library(qjs_comm STATIC ${QJS_COMM_SRC})

add_executable(qjsc qjsc.c)
target_link_libraries(qjsc qjs_comm)

qjsc_gen_file(TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/repl.js OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/repl.c GENERATOR qjsc)
qjsc_gen_file(TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/qjscalc.js OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c GENERATOR qjsc)

add_executable(qjs qjs.c ${CMAKE_CURRENT_BINARY_DIR}/repl.c ${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c)
target_link_libraries(qjs qjs_comm)